package com.clkj.sunhelp.mvp.main;

import android.Manifest;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.LinearLayout;

import com.clkj.sunhelp.R;
import com.clkj.sunhelp.adapter.vp.VpAdapterForBanner;
import com.clkj.sunhelp.mvp.base.BaseActivity;
import com.clkj.sunhelp.mvp.jobdeal.jobkindchoose.ActivityJobDealKindChoose;
import com.clkj.sunhelp.mvp.login.ActivityLogin;
import com.clkj.sunhelp.mvp.personlcenter.ActivityPersonlCenter;
import com.clkj.sunhelp.mvp.policyinfo.policykindchoose.ActivityPolicyKindChoose;
import com.clkj.sunhelp.mvp.publicityshow.ActivityPublicityMainView;
import com.clkj.sunhelp.mvp.seekhelpnew.list.ActivitySeekHelpToCiShanPage;
import com.clkj.sunhelp.util.ToastUtil;
import com.karumi.dexter.Dexter;
import com.karumi.dexter.MultiplePermissionsReport;
import com.karumi.dexter.PermissionToken;
import com.karumi.dexter.listener.PermissionRequest;
import com.karumi.dexter.listener.multi.MultiplePermissionsListener;
import com.rd.PageIndicatorView;

import java.util.ArrayList;
import java.util.List;

public class ActivityMain extends BaseActivity implements View.OnClickListener{

    //private TextView tvPolicyinfo;


    /*private TextView tvHelpshow;
    private TextView tvInfoSearch;
    private TextView tvJobDeal;
    private TextView tvQiuzhu;*/

    private LinearLayout layoutPolicy;
    private LinearLayout layoutHelpshow;
    private LinearLayout layoutSeekHelp;
    private LinearLayout layoutJobDeal;


    private ViewPager vpBanner;
    private PageIndicatorView pageindicatorBanner;




    VpAdapterForBanner mBannerAdapter;
    List<View> mViewList = new ArrayList<>();
    List<Integer> mLocalBannerResIdList = new ArrayList<>();








    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_new);
        initTitleWithRightTvOrIv(null,null,"阳光大救助平台",false,null,R.drawable.ico_head_default);
        initData();
        assignView();
        initView();
        requestPermission();
    }


    private void requestPermission()
    {
        Dexter.withActivity(this)
                .withPermissions(
                        Manifest.permission.CAMERA,
                        Manifest.permission.WRITE_EXTERNAL_STORAGE
                ).withListener(new MultiplePermissionsListener() {
            @Override public void onPermissionsChecked(MultiplePermissionsReport report) {
                /* ... */
                if (report.areAllPermissionsGranted())
                {

                }else {
                    ToastUtil.showShort(ActivityMain.this,"我们需要相机，本地存储权限用来保证软件的正常运行,请到系统设置里面进行相关设置");
                }
            }
            @Override public void onPermissionRationaleShouldBeShown(List<PermissionRequest> permissions, PermissionToken token) {
                /* ... */
                token.continuePermissionRequest();
            }
        }).check();
    }

    @Override
    public void initData() {

    }

    @Override
    public void assignView() {
        layoutPolicy = (LinearLayout) findViewById(R.id.layout_policy);
        layoutHelpshow = (LinearLayout) findViewById(R.id.layout_helpshow);
        layoutSeekHelp = (LinearLayout) findViewById(R.id.layout_seek_help);
        layoutJobDeal = (LinearLayout) findViewById(R.id.layout_job_deal);
        vpBanner = (ViewPager) findViewById(R.id.vp_banner);

        pageindicatorBanner = (PageIndicatorView) findViewById(R.id.pageindicator_banner);

    }

    @Override
    public void initView() {
        /*tvPolicyinfo.setOnClickListener(this);

        tvHelpshow .setOnClickListener(this);
        tvInfoSearch .setOnClickListener(this);
        tvJobDeal.setOnClickListener(this);
        ivRight.setOnClickListener(this);

        tvQiuzhu.setOnClickListener(this);*/

        for (int i = 0;i<3;i++)
        {
            View view = getLayoutInflater().inflate(R.layout.vp_item_banner,null);
            mViewList.add(view);
        }

        mLocalBannerResIdList.add(R.drawable.pic_banner_1);
        mLocalBannerResIdList.add(R.drawable.pic_banner_2);
        mLocalBannerResIdList.add(R.drawable.pic_banner_3);

        mBannerAdapter = new VpAdapterForBanner(this,mViewList,mLocalBannerResIdList);
        vpBanner.setAdapter(mBannerAdapter);
        pageindicatorBanner.setViewPager(vpBanner);

        layoutPolicy .setOnClickListener(this);
        layoutSeekHelp  .setOnClickListener(this);
        layoutHelpshow  .setOnClickListener(this);
        layoutJobDeal  .setOnClickListener(this);
        ivRight.setOnClickListener(this);


       /* layoutPolicy = (LinearLayout) findViewById(R.id.layout_policy);
        layoutInfosearch = (LinearLayout) findViewById(R.id.layout_infosearch);
        layoutHelpshow = (LinearLayout) findViewById(R.id.layout_helpshow);
        layoutJobDeal = (LinearLayout) findViewById(R.id.layout_job_deal);*/
    }

    @Override
    public void onClick(View view) {
        switch (view.getId())
        {
            /*case R.id.tv_policyinfo:
                startActivity(new Intent(ActivityMain.this, ActivityPolicyKindChoose.class));
                break;
            case R.id.tv_helpshow:
                startActivity(new Intent(ActivityMain.this, ActivityPublicityMainView.class));
                break;
            case R.id.tv_info_search:
                break;
            case R.id.tv_job_deal:
                break;*/
            case R.id.layout_policy:
                startActivity(new Intent(ActivityMain.this, ActivityPolicyKindChoose.class));
                break;
            case R.id.layout_helpshow:
                startActivity(new Intent(ActivityMain.this, ActivityPublicityMainView.class));
                break;

            case R.id.layout_job_deal:
                if (isLogin()==false)
                {

                    ToastUtil.showShort(ActivityMain.this,"请先登录");
                    startActivity(new Intent(this, ActivityLogin.class));

                }else {
                    startActivity(new Intent(ActivityMain.this, ActivityJobDealKindChoose.class));
                }

                break;

            case R.id.iv_right:
                if (isLogin()==false)
                {
                    ToastUtil.showShort(ActivityMain.this,"请先登录");
                    startActivity(new Intent(this, ActivityLogin.class));
                }else {

                    startActivity(new Intent(this, ActivityPersonlCenter.class));
                    //ToastUtil.showShort(ActivityMain.this,"账号已经登录");
                }

                break;
            case R.id.layout_seek_help:
                startActivity(new Intent(this, ActivitySeekHelpToCiShanPage.class));
                //startActivity(new Intent(this, ActivitySeekHelpHisListView.class));
                /*if (CommonUtil.getShareValue(SharePreKey.SP_KEY_LOGIN_TAG,false)) {

                }*/
                break;
            /*case R.id.tv_qiuzhu:
                startActivity(new Intent(this, ActivitySeekHelpHisListView.class));
                break;*/
        }
    }
}
